package com.foldingleaf.web.controller.author;

import com.foldingleaf.author.domain.SysCollectionAuthor;
import com.foldingleaf.author.service.ISysCollectionAuthorService;
import com.foldingleaf.common.annotation.Log;
import com.foldingleaf.common.core.controller.BaseController;
import com.foldingleaf.common.core.domain.Result;
import com.foldingleaf.common.core.page.TableDataInfo;
import com.foldingleaf.common.enums.BusinessType;
import com.foldingleaf.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.PermitAll;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 藏品作者Controller
 * 
 * @author ajian
 * @date 2022-05-30
 */
@Api(value = "/author/author" , tags = {"藏品作者Controller"})
@RestController
@RequestMapping("/author/author")
public class SysCollectionAuthorController extends BaseController
{
    @Autowired
    private ISysCollectionAuthorService sysCollectionAuthorService;

    /**
     * 查询藏品作者列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query" , dataType = "SysCollectionAuthor" , name = "sysCollectionAuthor" , value = "")
    })
    @ApiOperation(value = "查询藏品作者列表" , notes = "查询藏品作者列表" , httpMethod = "GET")
    @PermitAll
    @GetMapping("/list")
    public TableDataInfo list(SysCollectionAuthor sysCollectionAuthor)
    {
        startPage();
        List<SysCollectionAuthor> list = sysCollectionAuthorService.selectSysCollectionAuthorList(sysCollectionAuthor);
        return getDataTable(list);
    }

    /**
     * 导出藏品作者列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query" , dataType = "HttpServletResponse" , name = "response" , value = ""),
            @ApiImplicitParam(paramType = "query" , dataType = "SysCollectionAuthor" , name = "sysCollectionAuthor" , value = "")
    })
    @ApiOperation(value = "导出藏品作者列表" , notes = "导出藏品作者列表" , httpMethod = "POST")
    @PreAuthorize("@ss.hasPermi('author:author:export')")
    @Log(title = "藏品作者", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCollectionAuthor sysCollectionAuthor)
    {
        List<SysCollectionAuthor> list = sysCollectionAuthorService.selectSysCollectionAuthorList(sysCollectionAuthor);
        ExcelUtil<SysCollectionAuthor> util = new ExcelUtil<SysCollectionAuthor>(SysCollectionAuthor.class);
        util.exportExcel(response, list, "藏品作者数据");
    }

    /**
     * 获取藏品作者详细信息
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path" , dataType = "long" , name = "collectionAuthorId" , value = "")
    })
    @ApiOperation(value = "获取藏品作者详细信息" , notes = "获取藏品作者详细信息" , httpMethod = "GET")

    @GetMapping(value = "/{collectionAuthorId}")
    public Result getInfo(@PathVariable("collectionAuthorId") Long collectionAuthorId)
    {
        return Result.success(sysCollectionAuthorService.selectSysCollectionAuthorByCollectionAuthorId(collectionAuthorId));
    }

    /**
     * 新增藏品作者
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body" , dataType = "SysCollectionAuthor" , name = "sysCollectionAuthor" , value = "")
    })
    @ApiOperation(value = "新增藏品作者" , notes = "新增藏品作者" , httpMethod = "POST")
    @PreAuthorize("@ss.hasPermi('author:author:add')")
    @Log(title = "藏品作者", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody SysCollectionAuthor sysCollectionAuthor)
    {
        return toAjax(sysCollectionAuthorService.insertSysCollectionAuthor(sysCollectionAuthor));
    }

    /**
     * 修改藏品作者
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body" , dataType = "SysCollectionAuthor" , name = "sysCollectionAuthor" , value = "")
    })
    @ApiOperation(value = "修改藏品作者" , notes = "修改藏品作者" , httpMethod = "PUT")
    @PreAuthorize("@ss.hasPermi('author:author:edit')")
    @Log(title = "藏品作者", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody SysCollectionAuthor sysCollectionAuthor)
    {
        return toAjax(sysCollectionAuthorService.updateSysCollectionAuthor(sysCollectionAuthor));
    }

    /**
     * 删除藏品作者
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path" , dataType = "Long[]" , name = "collectionAuthorIds" , value = "")
    })
    @ApiOperation(value = "删除藏品作者" , notes = "删除藏品作者" , httpMethod = "DELETE")
    @PreAuthorize("@ss.hasPermi('author:author:remove')")
    @Log(title = "藏品作者", businessType = BusinessType.DELETE)
	@DeleteMapping("/{collectionAuthorIds}")
    public Result remove(@PathVariable Long[] collectionAuthorIds)
    {
        return toAjax(sysCollectionAuthorService.deleteSysCollectionAuthorByCollectionAuthorIds(collectionAuthorIds));
    }
}
